//
//  ViewController.m
//  28-AutoLayoutAnimation
//
//  Created by dllo on 16/8/22.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *centerY;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutLeft20;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutLeft150;

@property (nonatomic, copy) NSString *name;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.imageView.transform = CGAffineTransformMakeTranslation(0, -300);
}
- (IBAction)startAnimation:(id)sender {
//    // 改变centerY的constant
    self.centerY.constant = 200;
//    // 执行动画
//    [UIView animateWithDuration:1 animations:^{
//        // 必须调用 layoutIfNeeded, 调用后才能实现动画
//        [self.view layoutIfNeeded];
//    }];
    // 改变优先级(priority)
    // 约束的优先级, 改变时需要注意不能为1000, 程序会崩溃
    // 同一约束优先级高的会被执行, 优先级低的会被忽略
    self.layoutLeft20.priority = 752;
    self.layoutLeft150.priority = 750;
    [UIView animateWithDuration:1 animations:^{
        // 必须调用 layoutIfNeeded, 调用后才能实现动画
        [self.view layoutIfNeeded];
    }];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [UIView animateWithDuration:2 animations:^{
        self.imageView.transform = CGAffineTransformIdentity;
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
